<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 方式1：直接更换类名 -->
    <!-- <svg-icon :icon-class="isOn ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="handleToggle" /> -->
    <!-- 方式2：准备2套结构 -->
    <svg-icon v-if="isOn" icon-class="exit-fullscreen" class="fullscreen" @click="handleToggle" />
    <svg-icon v-else icon-class="fullscreen" class="fullscreen" @click="handleToggle" />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data () {
    return {
      isOn: false
    }
  },
  methods: {
    // 切换全屏
    handleToggle () {
      if (ScreenFull.isEnabled) {
        // 调用toggle()方法进行切换
        ScreenFull.toggle()
        this.isOn = !this.isOn
      } else {
        this.$message.warning('请升级浏览器')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
  margin-top: 17px;
  margin-right: 12px;
}
</style>
